package zuoye;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

import static org.junit.Assert.*;

public class gerenxiangmuTest {

    @org.junit.Test
    public void word() throws FileNotFoundException {
        File file=new File("d:\\aaa.txt");
        Scanner input=new Scanner(file);
        HashMap<String,Integer> hashMap=new HashMap<String,Integer>();
        while(input.hasNextLine()) {
            String line=input.nextLine();
            String[] lineWords=line.split("\\W+");
            Set<String> wordSet=hashMap.keySet();
            for(int i=0;i<lineWords.length;i++) {

                if(wordSet.contains(lineWords[i])) {
                    Integer number=hashMap.get(lineWords[i]);
                    number++;
                    hashMap.put(lineWords[i], number);
                }
                else {
                    hashMap.put(lineWords[i], 1);
                }
            }
        }
        for (String key : hashMap.keySet()) {
            System.out.println(key+"出现："+hashMap.get(key)+"次");
        }
    }
}